/**
  ******************************************************************************
  * @file    DCDC_Globals.h
  * @author  STMicroelectronics
  * @version 1.1.0
  * @date    09-Nov-2023
  * @brief   This file contains the declarations of the exported
  *                      variables of module "DCDC_globals.c".
  ******************************************************************************
  *
  * Copyright (c) 2022(-2023) Biricha Digital Power Limited
  * Copyright (c) 2014(-2023) STMicroelectronics.
  * All rights reserved.
  *
  * This software is licensed under terms that can be found in the LICENSE file in
  * the root directory of this software component.
  * If no LICENSE file comes with this software, it is provided AS-IS.
  ******************************************************************************
  *
  */

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __DCDC_GLOBALS_H
#define __DCDC_GLOBALS_H

/* Includes ------------------------------------------------------------------*/
#include "dpwr.h"
#include "DCDC_type.h"
#include "DPC_Miscellaneous.h"

/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* Exported variables --------------------------------------------------------*/
extern DCDC_MeasureStruct_t DCDC_MeasureStruct;          /**< Acquisition struct */

/* Filtered measures */
extern uint16_t hTemperatureFiltered;                   /**< Temperature filtered measure */
extern uint16_t hViperVoltageFiltered;                  /**< Viper voltage filtered measure -  NOT USED */
extern uint16_t hVoutVoltageFiltered;                   /**< Vout voltage filtered measure */
extern float fVrmsVoltageFiltered;                      /**< Input Vrms voltage filtered measure */

extern volatile float fTemperatureDeg;                  /**< LM19CIZ Temperature in deg */

/* Control variables */
extern __IO uint16_t hPhaseShift;                 	    /**< value of phase shift in HRTIM ticks */
extern volatile uint16_t hVout_Reference;               /**< Voltage out reference */
extern volatile uint16_t hVout_Reference_init;          /**< Voltage out reference init value */
//extern volatile uint16_t hVout_Reference_increment;   /**< Voltage out reference increment */

/* Start-up counters */
extern volatile uint16_t hDCDC_StartUp_TimeLeft;                /**< counter after init start-up DC/DC */
extern volatile uint16_t hDCDC_Wait_TimeLeft;                   /**< counter after enter in WAIT state */
extern volatile uint16_t hDCDC_UndervoltageValidation_TimeLeft; /**< counter to validate undervoltage protection */
extern volatile uint16_t hCommunicationTimeLeft;                /**< counter between two USART communications */
extern volatile uint16_t hLEDTaskTimeLeft;		                /**< counter between two LED tasks */

/* State variable of converter */
extern volatile DCDC_State_t DCDC_State;                /**< DCDC state variable */
extern volatile uint16_t DCDC_System_Fault;             /**< fault variable */
extern volatile uint16_t DCDC_Previous_System_Fault;    /**< previous DC/DC fault variable */
extern volatile uint16_t DCDC_Last_System_Fault;        /**< last fault variable value before stop application */
extern volatile uint16_t PFC_Received_Status;           /**< last PFC received status */
extern volatile uint16_t PFC_Last_System_Fault;         /**< last PFC fault variable */
#if (FAN_USAGE == true)
extern volatile uint16_t FAN_PWMDutyCycle;              /**< PWM duty cycle for fan control */
#endif

/* Boolean variables */
extern volatile bool bDCDC_OutputEnabled;               /**< TRUE when main PWMs of DCDC are enabled, FALSE otherwise */
#if (SYNCH_RECTIFICATION == true)
extern volatile bool bDCDC_SynchRectEnabled;            /**< TRUE when PWMs of Synch. Rect. are enabled, FALSE otherwise */
#endif
#if (ACTIVE_CLAMP == true)
extern volatile bool bDCDC_ActiveClampEnabled;          /**< TRUE when PWMs Active Clamp are enabled, FALSE otherwise */
#endif
extern volatile bool bCheckUndervoltageEnabled;         /**< TRUE when low out voltage short circuit fault is enabled, FALSE otherwise */
extern volatile bool bCheckOvertemperatureEnabled;      /**< TRUE when overtemperature fault is enabled, FALSE otherwise */
extern volatile bool bUpdateControlParamEnabled;        /**< TRUE when automatic update control parameters is enabled, FALSE otherwise */
#if (FAN_USAGE == true)
extern volatile bool bDCDC_FanEnabled;                  /**< TRUE when Fan is enabled, FALSE otherwise */
#endif
extern volatile bool bFirstFaultDetected;               /**< TRUE when the first fault to show with LED blinking was found, FALSE otherwise */
extern volatile bool bNonRecoverableError;              /**< TRUE when Error is not recoverable, FALSE otherwise */
extern volatile bool bNonRecoverableFault;              /**< TRUE when Fault is Not recoverable, FALSE otherwise */

/* Burst mode */
extern volatile bool bVoutBurstModeEnabled;             /**< TRUE when out voltage burst mode is active (Vbus> bm_threshold with hysteresis), FALSE otherwise */

extern volatile bool bDCDC_SecondarySynchRectEnabled;            /**< TRUE when PWMs of Synch. Rect. are enabled, FALSE otherwise */
extern SystStatus_key Key_USER_State;
/* Exported macro ------------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */

#endif /* __DCDC_GLOBALS_H */
